package cn.nubia.admin.application.controller;

import cn.nubia.admin.application.bean.SoftComment;
import cn.nubia.admin.application.bean.SoftCommentVO;
import cn.nubia.admin.application.query.SoftCommentQuery;
import cn.nubia.admin.application.service.SoftCommentService;
import cn.nubia.admin.common.mybatis.bean.Paged;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * 软件评论.
 */
@Controller
@RequestMapping(value = "/admin/soft/commment")
public class SoftCommentController {


    @Autowired
    private SoftCommentService softCommentService;

    /**
     * 草稿列表
     *
     * @return
     */
    @RequiresPermissions(value = "soft:app:commment:list")
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public ModelAndView list(SoftCommentQuery softCommentQuery) {
        ModelAndView modelAndView = new ModelAndView("/app/softCommmentList");
        Paged<SoftCommentVO> softComments = softCommentService.findPagedList(softCommentQuery);

        modelAndView.addObject("fromType", "listDraft");
        modelAndView.addObject("softComments", softComments);
        modelAndView.addObject("query", softCommentQuery);
        return modelAndView;
    }


    @RequestMapping(value = "view")
    public ModelAndView view(Integer id){
        ModelAndView modelAndView = new ModelAndView("/app/softCommentView");
        SoftComment softComment = softCommentService.get(id);
        modelAndView.addObject("softComment",softComment);
        return modelAndView;
    }



    @RequestMapping(value = "delete")
    public String delete(Integer id){
        softCommentService.changeState(id, SoftComment.STATE_DEL);
        return "redirect:list.html";
    }

    @RequestMapping(value = "hidden")
    public String hidden(Integer id){
        softCommentService.changeState(id, SoftComment.STATE_HIDDEN);
        return "redirect:list.html";
    }




}
